package com.ruoyi.web.controller.warning;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.warning.domain.entity.Dispose;
import com.ruoyi.warning.service.IDisposeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 告警事件处理表 前端控制器
 * </p>
 *
 * @author chenhc
 * @since 2025-05-16
 */
@RestController
@RequestMapping("/dispose")
@Api(tags = "处理", description = "用于事件处理相关操作的控制器")
public class DisposeController {
    @Resource
    private IDisposeService disposeService;
    @ApiOperation("处理事件")
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @PostMapping(value = "/dispose")
    public R dispose(@RequestBody Dispose dispose) throws Exception {
        return R.ok(disposeService.dispose(dispose));
    }

    @ApiOperation("批量处理事件")
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @PostMapping(value = "/batchDispose")
    public R batchDispose(@RequestBody List<Dispose> list) throws Exception {
        for(Dispose dispose:list){
            disposeService.dispose(dispose);
        }
        return R.ok("成功");
    }

    @ApiOperation("处理详情")
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/detail")
    public R detail(String eventId)
    {
        LambdaQueryWrapper<Dispose> queryWrapper = new QueryWrapper<Dispose>().lambda()
                .eq(Dispose::getEventId, eventId);
        return R.ok(disposeService.getOne(queryWrapper));
    }
}
